package org.insia.smartposse.struts.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.insia.smartposse.config.DAOFactory;
import org.insia.smartposse.metier.User;

public class ShowProjects extends DispatchAction {
	protected final Logger log = Logger.getLogger(getClass());
	
	@Override
	public ActionForward unspecified(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response)
	throws Exception {
		
		log.info("Dans: ShowDashboardAction");
		
		if (request.getSession().getAttribute("user") instanceof User) {
			List<org.insia.smartposse.metier.Project> projectLeader = DAOFactory.getProjectDAO().getList();
			
			request.setAttribute("projects", projectLeader);
		}
		
		return mapping.findForward("show");
	}
	
	
	public ActionForward addToMe(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) 
    throws Exception {
		// User currentUser = (User)request.getSession().getAttribute("user");
		// attente des methodes DAO pour affectation d'une personne à un projet
		
    	List<String> messages = new ArrayList<String>();
    	request.setAttribute("messages", messages);
    	
    	messages.add("not implemented yet! come back later Tako!");
		
		return mapping.findForward("show");		
	}
} 
	
